package yunjiao.designpatterns.interpreter;

import java.util.Map;

/**
 * TODO
 *
 * @author yangyunjiao
 */
public abstract class TerminalExpression implements Expression {
    public static class VariableExpression extends TerminalExpression {
        private final String variable;

        public VariableExpression(String variable) {
            this.variable = variable;
        }

        @Override
        public int interpret(Map<String, Integer> context) {
            return context.getOrDefault(variable, 0);
        }
    }

    public static class ConstantExpression extends TerminalExpression {
        private final int value;

        public ConstantExpression(int value) {
            this.value = value;
        }

        @Override
        public int interpret(Map<String, Integer> context) {
            return value;
        }
    }
}
